package com.cee.controller;


import com.cee.common.result.Result;
import com.cee.dto.*;

import com.cee.model.*;

import com.cee.service.*;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/select")
@RestController
public class SelectController {

    @Autowired
    private OneTypeService oneTypeService;

    @Autowired
    private OneTwoTypeService oneTwoTypeService;

    @Autowired
    private OneSelectService oneSelectService;

    @Autowired
    private ManySelectService manySelectService;

    @Autowired
    private JudgeService judgeService;

    @Autowired
    private CompletionService completionService;

    @Autowired
    private ShortAnswerService shortAnswerService;

    @Autowired
    private ExamService examService;


    @GetMapping("/oneType")
    public Result getOneTypeSelects() {

        List<OneType> oneTypes = oneTypeService.getOneTypeList();

        List<SelectDTO> list = new ArrayList<>();
        for (OneType oneType : oneTypes) {
            SelectDTO selectDTO = new SelectDTO(Integer.toString(oneType.getId()), oneType.getOneTypeName());
            list.add(selectDTO);
        }
        return Result.ok(list);
    }


    @GetMapping("/twoType")
    public Result getTwoTypeSelects(String oneTypeId) {

        List<TwoType> twoTypeDTOS = oneTwoTypeService.getOneTwoTypeByOneType(oneTypeId);

        List<SelectDTO> list = new ArrayList<>();
        for (TwoType twoType : twoTypeDTOS) {
            SelectDTO selectDTO = new SelectDTO(Integer.toString(twoType.getId()), twoType.getTwoTypeName());
            list.add(selectDTO);
        }
        return Result.ok(list);
    }


    @PostMapping("/oneSelect")
    public Result getOneSelects(@RequestBody OneSelectDTO oneSelectDTO){

        List<OneSelectDTO> oneSelects = oneSelectService.getOneSelectList(oneSelectDTO);

        List<SelectDTO> list = new ArrayList<>();
        for (OneSelect oneSelect : oneSelects) {
            SelectDTO selectDTO = new SelectDTO( Integer.toString(oneSelect.getId()), oneSelect.getTitle() );
            list.add(selectDTO);
        }

        return Result.ok(list);
    }

    @PostMapping("/manySelect")
    public Result getManySelects(@RequestBody ManySelectDTO manySelectDTO){

        List<ManySelectDTO> manySelects = manySelectService.getManySelectList(manySelectDTO);

        List<SelectDTO> list = new ArrayList<>();
        for (ManySelect manySelect : manySelects) {
            SelectDTO selectDTO = new SelectDTO( Integer.toString(manySelect.getId()), manySelect.getTitle() );
            list.add(selectDTO);
        }

        return Result.ok(list);
    }


    @PostMapping("/judge")
    public Result getJudges(@RequestBody JudgeDTO judgeDTO){

        List<JudgeDTO> judges = judgeService.getJudgeList(judgeDTO);

        List<SelectDTO> list = new ArrayList<>();
        for (Judge judge : judges) {
            SelectDTO selectDTO = new SelectDTO( Integer.toString(judge.getId()), judge.getTitle() );
            list.add(selectDTO);
        }

        return Result.ok(list);
    }

    @PostMapping("/completion")
    public Result getCompletions(@RequestBody CompletionDTO completionDTO){

        List<CompletionDTO> completions = completionService.getCompletionList(completionDTO);

        List<SelectDTO> list = new ArrayList<>();
        for (Completion completion : completions) {
            SelectDTO selectDTO = new SelectDTO( Integer.toString(completion.getId()), completion.getTitle() );
            list.add(selectDTO);
        }

        return Result.ok(list);
    }


    @PostMapping("/shortAnswer")
    public Result getShortAnswers(@RequestBody ShortAnswerDTO shortAnswerDTO){

        List<ShortAnswerDTO> shortAnswers = shortAnswerService.getShortAnswerList(shortAnswerDTO);

        List<SelectDTO> list = new ArrayList<>();
        for (ShortAnswer shortAnswer : shortAnswers) {
            SelectDTO selectDTO = new SelectDTO( Integer.toString(shortAnswer.getId()), shortAnswer.getTitle() );
            list.add(selectDTO);
        }

        return Result.ok(list);
    }


    @PostMapping ("/examDataList")
    public Result getExamDataList(){

        List<SelectDTO> list = new ArrayList<>();

        Exam exam = new Exam();
        List<ExamDTO> examDTOS =  examService.getExamList(exam);
        for (ExamDTO examDTO : examDTOS) {
            SelectDTO selectDTO = new SelectDTO( Integer.toString(examDTO.getId()), examDTO.getExamName() );
            list.add(selectDTO);
        }

        return Result.ok(list);
    }



//    @PostMapping("/shortAnswer")
//    public Result getShortAnswers(@RequestBody ShortAnswerDTO shortAnswerDTO){
//
//        List<ShortAnswerDTO> shortAnswers = shortAnswerService.getShortAnswerList(shortAnswerDTO);
//
//        List<SelectDTO> list = new ArrayList<>();
//        for (ShortAnswer shortAnswer : shortAnswers) {
//            SelectDTO selectDTO = new SelectDTO( Integer.toString(shortAnswer.getId()), shortAnswer.getTitle() );
//            list.add(selectDTO);
//        }
//
//        return Result.ok(list);
//    }


}
